from pathlib import PurePath
from typing import Any, Callable

from infection_monkey.exploit.tools import IRemoteAccessClientFactory
from infection_monkey.i_puppet import TargetHost

from .smb_client import SMBClient
from .smb_options import SMBOptions
from .smb_remote_access_client import SMBRemoteAccessClient
from .wmi_client import WMIClient
from .wmi_options import WMIOptions
from .wmi_remote_access_client import WMIRemoteAccessClient


class WMIRemoteAccessClientFactory(IRemoteAccessClientFactory):
    def __init__(
        self,
        host: TargetHost,
        options: WMIOptions,
        command_builder: Callable[[PurePath], str],
    ):
        self._host = host
        self._options = options
        self._command_builder = command_builder

    def create(self, **kwargs: Any) -> WMIRemoteAccessClient:
        smb_options = SMBOptions(
            agent_binary_upload_timeout=self._options.agent_binary_upload_timeout,
            smb_connect_timeout=self._options.smb_connect_timeout,
        )
        smb_client = SMBRemoteAccessClient(self._host, smb_options, lambda _, __: "", SMBClient())
        return WMIRemoteAccessClient(
            self._host, self._options, self._command_builder, smb_client, WMIClient()
        )
